﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => MAP_FUNCTION
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 12:01:54
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;
using DataAccess.Interface;

#endregion

namespace DataAccess.Dal
{
    internal class MapFunctionDal //: IResponsible<Prop.MapFunction>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static MapFunctionDal _dal;

        private System.String sql = "";


        public static MapFunctionDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new MapFunctionDal();

            return _dal;
        }

        public IEnumerable<Prop.MapFunction> Select(Prop.MapFunction obj)
        {
            IEnumerable<Prop.MapFunction> entities = new List<Prop.MapFunction>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.EDIT_FLAG))
                    {
                        concast.Append(" AND EDIT_FLAG=:EDIT_FLAG ");
                        hashtable.Add(":EDIT_FLAG", obj.EDIT_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.DELETE_FLAG))
                    {
                        concast.Append(" AND DELETE_FLAG=:DELETE_FLAG ");
                        hashtable.Add(":DELETE_FLAG", obj.DELETE_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.SEARCH_FLAG))
                    {
                        concast.Append(" AND SEARCH_FLAG=:SEARCH_FLAG ");
                        hashtable.Add(":SEARCH_FLAG", obj.SEARCH_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.REPORT_FLAG))
                    {
                        concast.Append(" AND REPORT_FLAG=:REPORT_FLAG ");
                        hashtable.Add(":REPORT_FLAG", obj.REPORT_FLAG);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsDate(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.GROUPNO))
                    {
                        concast.Append(" AND GROUPNO=:GROUPNO ");
                        hashtable.Add(":GROUPNO", obj.GROUPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNO))
                    {
                        concast.Append(" AND FUNCNO=:FUNCNO ");
                        hashtable.Add(":FUNCNO", obj.FUNCNO);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.ACCESS_FLAG))
                    {
                        concast.Append(" AND ACCESS_FLAG=:ACCESS_FLAG ");
                        hashtable.Add(":ACCESS_FLAG", obj.ACCESS_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.ADD_FLAG))
                    {
                        concast.Append(" AND ADD_FLAG=:ADD_FLAG ");
                        hashtable.Add(":ADD_FLAG", obj.ADD_FLAG);
                    }

                }
                sql = System.String.Format(@" SELECT EDIT_FLAG ,DELETE_FLAG ,SEARCH_FLAG ,REPORT_FLAG ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,APPLNO ,GROUPNO ,FUNCNO ,COMPANY_CODE ,ACCESS_FLAG ,ADD_FLAG  FROM MAP_FUNCTION");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.MapFunction>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public Boolean Add(Prop.MapFunction obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO MAP_FUNCTION(EDIT_FLAG ,DELETE_FLAG ,SEARCH_FLAG ,REPORT_FLAG ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,APPLNO ,GROUPNO ,FUNCNO ,COMPANY_CODE ,ACCESS_FLAG ,ADD_FLAG )
					VALUES(:EDIT_FLAG ,:DELETE_FLAG ,:SEARCH_FLAG ,:REPORT_FLAG ,:CRDATE ,:CRBY ,:UPDDATE ,:UPDBY ,:APPLNO ,:GROUPNO ,:FUNCNO ,:COMPANY_CODE ,:ACCESS_FLAG ,:ADD_FLAG ");

                hashtable = new Hashtable();
                hashtable.Add(":EDIT_FLAG", obj.EDIT_FLAG);
                hashtable.Add(":DELETE_FLAG", obj.DELETE_FLAG);
                hashtable.Add(":SEARCH_FLAG", obj.SEARCH_FLAG);
                hashtable.Add(":REPORT_FLAG", obj.REPORT_FLAG);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":CRBY", obj.CRBY);
                hashtable.Add(":UPDDATE", obj.UPDDATE);
                hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":GROUPNO", obj.GROUPNO);
                hashtable.Add(":FUNCNO", obj.FUNCNO);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":ACCESS_FLAG", obj.ACCESS_FLAG);
                hashtable.Add(":ADD_FLAG", obj.ADD_FLAG);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Update(Prop.MapFunction obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE MAP_FUNCTION
					SET
					EDIT_FLAG=:EDIT_FLAG,
					DELETE_FLAG=:DELETE_FLAG,
					SEARCH_FLAG=:SEARCH_FLAG,
					REPORT_FLAG=:REPORT_FLAG,
					CRDATE=:CRDATE,
					CRBY=:CRBY,
					UPDDATE=:UPDDATE,
					UPDBY=:UPDBY,
					APPLNO=:APPLNO,
					GROUPNO=:GROUPNO,
					FUNCNO=:FUNCNO,
					COMPANY_CODE=:COMPANY_CODE,
					ACCESS_FLAG=:ACCESS_FLAG,
					ADD_FLAG=:ADD_FLAG");

                hashtable = new Hashtable();
                hashtable.Add(":EDIT_FLAG", obj.EDIT_FLAG);
                hashtable.Add(":DELETE_FLAG", obj.DELETE_FLAG);
                hashtable.Add(":SEARCH_FLAG", obj.SEARCH_FLAG);
                hashtable.Add(":REPORT_FLAG", obj.REPORT_FLAG);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":CRBY", obj.CRBY);
                hashtable.Add(":UPDDATE", obj.UPDDATE);
                hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":GROUPNO", obj.GROUPNO);
                hashtable.Add(":FUNCNO", obj.FUNCNO);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":ACCESS_FLAG", obj.ACCESS_FLAG);
                hashtable.Add(":ADD_FLAG", obj.ADD_FLAG);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Delete(Prop.MapFunction obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.EDIT_FLAG))
                    {
                        concast.Append(" AND EDIT_FLAG=:EDIT_FLAG ");
                        hashtable.Add(":EDIT_FLAG", obj.EDIT_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.DELETE_FLAG))
                    {
                        concast.Append(" AND DELETE_FLAG=:DELETE_FLAG ");
                        hashtable.Add(":DELETE_FLAG", obj.DELETE_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.SEARCH_FLAG))
                    {
                        concast.Append(" AND SEARCH_FLAG=:SEARCH_FLAG ");
                        hashtable.Add(":SEARCH_FLAG", obj.SEARCH_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.REPORT_FLAG))
                    {
                        concast.Append(" AND REPORT_FLAG=:REPORT_FLAG ");
                        hashtable.Add(":REPORT_FLAG", obj.REPORT_FLAG);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsDate(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.GROUPNO))
                    {
                        concast.Append(" AND GROUPNO=:GROUPNO ");
                        hashtable.Add(":GROUPNO", obj.GROUPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNO))
                    {
                        concast.Append(" AND FUNCNO=:FUNCNO ");
                        hashtable.Add(":FUNCNO", obj.FUNCNO);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.ACCESS_FLAG))
                    {
                        concast.Append(" AND ACCESS_FLAG=:ACCESS_FLAG ");
                        hashtable.Add(":ACCESS_FLAG", obj.ACCESS_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.ADD_FLAG))
                    {
                        concast.Append(" AND ADD_FLAG=:ADD_FLAG ");
                        hashtable.Add(":ADD_FLAG", obj.ADD_FLAG);
                    }

                }
                sql = System.String.Format(@" DELETE FROM MAP_FUNCTION ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/

